<script src="/jquery-ui-1.8.custom/development-bundle/jquery-1.4.2.js"></script>
<script src="/jquery-validate/jquery.validate.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" media="screen" href="/jquery-validate/demo/css/screen.css" />
<?php 
if (isset($_SESSION['error_messages'])){

	echo "<div id='error_msg'>";

	foreach($_SESSION['error_messages'] as $msg){
		echo "<li>".$msg."</li>\n";
	 }

	echo "</div>";
	unset($_SESSION['error_messages']);
}?>

<div >
<form id="user_add" enctype="application/x-www-form-urlencoded" method="post" action="/user/create" >
<fieldset>
username: <input type="text" name="username" size=10/>
<br><p/>
password: <input id="password" name="password" type="password" size=10/>
<p/>
<br><p/>
confirm password: <input name="confirm_password" type="password" size=10/>
<p/>
<br><p/>
nick name: <input name="nickname" type="text" size=10/>
<p/>
<input type="submit" value="register"/>&nbsp;&nbsp;
<input type="button" value="cancel"/>
</fieldset>
</form>
</div>

<script type="text/javascript">
$.validator.setDefaults({
	//submitHandler: function() { alert("submitted!"); }
});

$().ready(function() {
	
	// validate signup form on keyup and submit
	$("#user_add").validate({
		rules: {
			username: {
				required: true,
				minlength: 2
			},
			password: {
				required: true,
				minlength: 1
			},
			confirm_password: {
				required: true,
				minlength: 1,
				equalTo: "#password"
			},
			nickname: {
				required: true,
				minlength: 2
			}
		},
		messages: {
			username: {
				required: "Please enter a username",
				minlength: "Your username must consist of at least 2 characters"
			},
			password: {
				required: "Please provide a password",
				minlength: "Your password must be at least 2 characters long"
			},
			confirm_password: {
				required: "Please provide a password",
				minlength: "Your password must be at least 2 characters long",
				equalTo: "Please enter the same password as above"
			},
			nickname: {
				required: "Please provide a nick name",
				minlength: "Your nick name must be at least 2 characters long"
			}
		}
	});
});
</script>

